﻿Imports System.Globalization

Public Class HalfValueConverter
    Implements IMultiValueConverter

#Region "IMultiValueConverter Members"

    Public Function Convert(values As Object(), targetType As Type, parameter As Object, culture As CultureInfo) _
        As Object Implements IMultiValueConverter.Convert
        If values Is Nothing OrElse values.Length < 2 Then
            Throw _
                New ArgumentException( _
                                       "HalfValueConverter expects 2 double values to be passed" & _
                                       " in this order -> totalWidth, width", "values")
        End If

        Dim totalWidth As Double = CDbl(values(0))
        Dim width As Double = CDbl(values(1))
        Return DirectCast((totalWidth - width) / 2, Object)
    End Function

    Public Function ConvertBack(value As Object, targetTypes As Type(), parameter As Object, culture As CultureInfo) _
        As Object() Implements IMultiValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function

#End Region
End Class